package com.example.common.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import org.springframework.http.ResponseEntity;
import lombok.Data;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@ApiModel(description = "通用响应对象")
public class BaseResponse<T> {
    @ApiModelProperty("状态码")
    private int code;
    
    @ApiModelProperty("消息")
    private String message;
    
    @ApiModelProperty("数据")
    private T data;

    public BaseResponse(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    // 添加无参构造函数
    public BaseResponse() {
    }

    public static ResponseEntity<BaseResponse<Void>> error(String message) {
        return ResponseEntity.status(500).body(new BaseResponse<Void>(500, message, null));
    }

    public BaseResponse<T> code(int code) {
        this.code = code;
        return this;
    }

    // Getters and Setters
}